package com.csyf.manager.controller.merchant;

import com.csyf.manager.entity.BalanceShowVo;
import com.csyf.manager.entity.SysMerchant;
import com.csyf.manager.entity.SysUser;
import com.csyf.manager.service.ProxyQueryBiz;
import com.csyf.manager.service.SysMerchBiz;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author: casper
 * @Description: 商户信息Controller
 * @Date: Created in 2018/11/30 15:52
 */
@Controller
@RequestMapping("/merch")
public class MerchInfoController {

    @Autowired
    private SysMerchBiz sysMerchBiz;

    @Autowired
    private ProxyQueryBiz proxyQueryBiz;

    /**
     * 商户信息展示
     * @param model
     * @return
     */
    @GetMapping(value = "merchInfo")
    public String merchInfo(Model model) {

        SysMerchant agentInfo = getAgentInfo();
        model.addAttribute("merch",agentInfo);
        return "merchant/merchInfo";
    }

    /**
     * 商户余额列表
     * @param model
     * @return
     */
    @GetMapping(value = "merchAccBalance")
    public String merchAccBalance(Model model) {

        SysMerchant agentInfo = getAgentInfo();

        List<BalanceShowVo> showVos = proxyQueryBiz.queryBalance(agentInfo.getMerchMerchantNo());
        model.addAttribute("list", showVos);
        return "merchant/merchAccBalance";
    }



    public SysMerchant getAgentInfo() {
        SysUser sysUser = (SysUser) SecurityUtils.getSubject().getPrincipal();
        SysMerchant agent = sysMerchBiz.queryAgentByUserId(sysUser.getUserId());
        return agent;
    }



}
